package org.example;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @author TonySong
 * @date 2025/7/30 0030
 * @time 14:15
 */
public class Test2 {
    public static void main(String[] args) {
        Class<User> userClass = User.class;
        System.out.println("User类的简单的名称："+userClass.getSimpleName());
        System.out.println("User的父类名："+userClass.getSuperclass().getName());
        System.out.println("User的父类名："+userClass.getSuperclass().getSimpleName());
        Class<?>[] interfaces = userClass.getInterfaces();
        if(interfaces.length>0) {
            for (Class<?> cf : interfaces) {
                System.out.println("接口的名称"+cf.getName());
                Method[] methods = cf.getMethods();
                for(Method method: methods){
                    System.out.println("方法名："+method.getName());
                    System.out.println("方法的访问级别："+Modifier.toString(method.getModifiers()));
                    System.out.println("方法的返回值类型："+method.getReturnType().getName());
                    Class<?>[] parameterTypes = method.getParameterTypes();
                    System.out.print("方法的参数类型：");
                    for(Class<?> c:parameterTypes){
                        System.out.print(c.getName()+" ");
                    }
                    System.out.println();
                }
            }
        }else{
            System.out.println("没有实现接口");
        }

        Field[] fields = userClass.getFields();
        System.out.println("User及其父类，public的属性：");
        for(Field field:fields){
            System.out.println(""+field.getName()+
                    "访问级别"+ Modifier.toString(field.getModifiers()));
        }
        Field[] fs = userClass.getDeclaredFields();
        System.out.println("User的属性：");
        for(Field field:fs){
            System.out.println(""+field.getName()+
                    "访问级别"+ Modifier.toString(field.getModifiers()));
        }
    }
}
